﻿using System;
using System.Collections.Generic;
using System.Linq;
using Interface;

namespace Model
{
    public class RidCollection
    {
        public List<Rid> RidCol { get; set; }

        public RidCollection()
        {
            RidCol = new List<Rid>();
        }

        #region Methods
        public Rid Add(long rid, string entity, DateTime createDate, DateTime updateDate, bool deleted, bool hidden,
                        bool disabled, string synUUid)
        {
            Rid _rid = new Rid(rid, entity, createDate, updateDate, deleted, hidden, disabled, synUUid);
            RidCol.Add(_rid);
            return _rid;
        }
        public IRid FindRid(long rid)
        {
            int max = RidCol.Count;
            int min = 0;

            while (max >= min)
            {
                int mid = (max + min) / 2;

                if (RidCol[mid].RId < rid)
                    min = mid + 1;
                else if (RidCol[mid].RId > rid)
                    max = mid - 1;
                else
                    return RidCol[mid];
            }
            return null;
        }
        public IRid GetLastRid()
        {
            return RidCol.Last();
        }
        #endregion
    }
}